package edu.gdit.health.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import edu.gdit.health.base.Results;
import edu.gdit.health.model.SysDict;
import edu.gdit.health.model.SysReport;
import edu.gdit.health.service.SysReportService;

@Controller
@RequestMapping("report")
public class SysReportController {
	@Autowired
	private SysReportService sysReportService;

	@GetMapping("add")
	public ModelAndView add(ModelAndView model) {
		// 定义一个获取数据字典的对象dict
		Map<String, List<SysDict>> dict = sysReportService.getTypes();
		// 将dict返回到前端页面

		model.addObject("dict", dict);
		model.setViewName("report/add.html");
		return model;
	}

	@PostMapping("add")
	@ResponseBody
	public int add(@RequestBody SysReport sysReport) {
		return sysReportService.add(sysReport);
	}
	/*
	 * @GetMapping(value = "chart/refresh")
	 * 
	 * @ResponseBody public Results refresh() { return sysReportService.refresh(); }
	 */
    @GetMapping(value = "chart/temperature")
    @ResponseBody
    public Results chartTemperature() {
        return sysReportService.getChartTemperatureData();
    }
}
